package net.neptech.model.sys;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import jakarta.persistence.*;
import lombok.Data;
import net.neptech.utils.SnowflakeIdGenerator;
import org.hibernate.annotations.GenericGenerator;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author Saya
 * @Date 2025/8/12 15:43
 * @Description TODO
 **/
@Entity
@Table(name = "sys_dept")
@TableName("sys_dept")
@Data
public class Dept implements Serializable {
    @Id
    @GenericGenerator(name = "snowflake", type = SnowflakeIdGenerator.class)
    @GeneratedValue(generator = "snowflake")
    @Column(name = "dept_id", nullable = false)
    @TableId
    @JsonSerialize(using = ToStringSerializer.class)
    private Long deptId;
    @Serial
    private static final long serialVersionUID = 1L;
    @Column(name = "dept_no")
    private String deptNo;
    @Column(name = "dept_name")
    private String deptName;
    @Column(name = "description")
    private String description;
    @Column(name = "leader")
    private Long leader;
    @Column(name = "phone")
    private String phone;
    @Column(name = "parent_id")
    private Long parentId;
    @Column(name = "ancestors")
    private String ancestors;
    @Column(name = "manager_id")
    private Long managerId;
    @Transient
    @TableField(exist = false)
    private String parentName;

    /**
     * 子部门
     */
    @Transient
    @TableField(exist = false)
    private List<Dept> children = new ArrayList<>();
}
